# -*- coding: utf-8 -*-

from PyQt4 import QtGui, QtCore
from question import Question


class True_False(Question):
    def __init__(self):
        super(True_False, self).__init__()

        self.questionName = self.tr("True / False")
        self.setObjectName("True_False")

        self.ui.addAnswerButton.setDisabled(True)
        self.ui.answersWidget.setTitle(self.tr("Answer"))

        answerLabel = QtGui.QLabel(self.tr("Correct answer"))
        self.ui.answersLayout.addWidget(answerLabel, 0, 0)

        self.trueQuestion = QtGui.QRadioButton(self.tr("Yes"))
        # defaultne zaskrtnu true odpoved
        self.trueQuestion.setChecked(True)
        self.falseQuestion = QtGui.QRadioButton(self.tr("No"))

        self.ui.answersLayout.addWidget(self.trueQuestion, 1, 0)
        self.ui.answersLayout.addWidget(self.falseQuestion, 1, 1)

        self.defaultAnswers = None

    def addAnswer(self, data):

        # sice je to asi zlehka prasarna, ale jednodussi reseni me nenapadlo
        # znasilnime tuto metodu aby nam nastavila widgety pri otevirani True/False otazky ze souboru
        # modifikaci teto metody se nepouzije ta zdedena z question a tahle zaridi vse potrebne
        # v argumentu data mame string FALSE nebo TRUE, podle toho nastavime zaskrtnuti spinboxu
        if data[0] == "TRUE":
            self.trueQuestion.setChecked(True)
        else:
            self.falseQuestion.setChecked(True)


    def validateQuestion(self):
        """ kontrola validity otazky """

        self.basicValidate()


    def getData(self):
        """ vraci otazku v GIFT formatu, pouziva se pri ulozeni a nahledu otazky """

        # text otazky
        questionText = self.getQuestion()
        # nazev otazky
        questionTitle = self.getQuestionTitle()
        out = QtCore.QString("%1%2 {").arg(questionTitle).arg(questionText)

        if self.trueQuestion.isChecked():
            answer = "TRUE"
        else:
            answer = "FALSE"

        out.append("\n")
        out.append(QtCore.QString("\t%1").arg(answer))
        out.append("\n")
        out.append(QtCore.QString("}"))
        out.append("\n")
        
        return out
		